<template>
  <div class="login">
    <img class="img" src="//award.xmcdn.com/yx/fe-passport/last/dist/images/new-logo-m@2x_2909eca.png" alt="">
    <div >
      <van-tabs  color="#ff4613" line-width="160px" title-active-color="#ff4613">
        <van-tab title="验证码登录">
          <van-cell-group inset >
            <!-- 输入手机号，调起手机号键盘 -->
            <van-field v-model="phone" type="tel" label="手机号"/>
          </van-cell-group>
        </van-tab>
        <van-tab title="密码登录">
          <van-cell-group inset>
            <!-- 输入手机号，调起手机号键盘 -->
            <van-field v-model="phone" type="tel" label="手机号" />
            <!-- 输入密码 -->
            <van-field v-model="password" type="password" label="密码" />
          </van-cell-group></van-tab>
      </van-tabs>
    </div>
    <button class="denglu" :class="{'deng':phone && password}" @click="clickHandler">
      登录
    </button>
    <span class="em">邮箱登录</span>
    <div class="text">
      <div style="margin-top:10px;">
        <van-checkbox v-model="checked" checked-color="#ff4613" icon-size="15"></van-checkbox>
      </div>
      
      <p>首次登录会自动创建新账号，且代表同意<span>《用户服务协议》</span>和<span>《隐私政策》</span></p>
    </div>
    <div class="footer">

      <!-- <span>其它登录方式</span> -->
      <van-divider class="footer_text">其它登录方式</van-divider>

      <div class="icon">
        <van-icon name="qq" size="48" color="#29b4e8"/>
        <van-icon name="weibo" size="48" color="#ec5e5e"/>
      </div>
      
    </div>
  </div>
</template>

<script setup lang="ts">
import {ref} from 'vue'
// import {reqLogin} from '../../api/login/index'
import { showToast } from 'vant';
import {useUserStore} from '../../store/user/index'
import {useRouter,useRoute} from 'vue-router'
const phone = ref('')
const password = ref('')
const checked = ref(true);
const userStore=useUserStore();
const router=useRouter();
const route=useRoute();
// 点击登录
const clickHandler = async() => {
  if(!checked.value) {
    showToast('请勾选协议！');
    return 
  }
  let reg = /^1[3-9]\d{9}$/
  if(!reg.test(phone.value)) {
    showToast('手机号格式错误');
    return
  }
  if(password.value.length < 6){
    showToast('密码格式错误');
    return
  }
  await userStore.getLogin(phone.value,password.value);
  let path=(route.query.redirect as string);
  
  
  if(path){
    router.push(path)
  }else{
    router.push({
    path:'/home'
  })
  }
 
}
</script>

<style lang="less" scoped>
.login {
  display: flex;
  flex-direction: column;
  align-items: center;


}

.img {
  width: 177px;
  height: 74.58px;
  margin-top: 40px;
  margin-bottom: 40px;
}

.denglu {
  width: 295px;
  height: 48px;
  background: #E8E8E8;
  border-radius: 30px;
  text-align: center;
  line-height: 48px;
  font-size: 16px;
  color: #FFF;
  border: none;
  
  
}
.deng {
 background: #ff4613; 
}
.em {
  font-size: 12px;
  color: #333;
  margin-top: 20px;
  margin-left: -220px;
}
.text {
  width: 295px;
  height: 36px;
  font-size: 12px;
  color: #999;
  display: flex;
  margin-left: 23px;
  p{
    // margin-left: 5px;
    text-align: center;
  }
  span{
    color: #ff4613;
  }
}
.footer {
  width: 100%;
  height: 152px;
  font-size: 12px;
  color: #999;
  margin-top: 150px;
  text-align:center;
  position: fixed; 
  bottom: 0

}
.icon {
  margin-top: 20px;
  display: flex;
  justify-content: space-between;
  padding: 0 100px;
}
.footer_text {
  padding: 0 40px;
}


</style>